package com.acyouzi.xiaomi;

import java.util.HashMap;
import java.util.Scanner;

/**
 * 17/9/18 19:50
 *
 * @author sunxu
 */

class TrieNode {
  public String val;
  public boolean isend;
  public HashMap<String,TrieNode> map = new HashMap<>();
  TrieNode(String str,boolean isend){
    this.val = str;
    this.isend = isend;
  }
  @Override
  public boolean equals(Object obj) {
    return ((TrieNode) obj).val.equals(this.val);
  }
}
public class Path {
  public static TrieNode root = new TrieNode("",false);
  public static void insert(String path,String val) {
    TrieNode tmp = root;
    String[] arr = path.split("/");
    for (int i = 0; i < arr.length; i++) {
      if (!tmp.map.containsKey(arr[i])){
        tmp.map.put(arr[i],new TrieNode("",false));
      }
      tmp = tmp.map.get(arr[i]);
    }
    tmp.isend = true;
    tmp.val = val;
  }
  public static String search (String path){
    TrieNode tmp = root;
    String[] arr = path.split("/");
    int i = 0;
    String res = "0";
    while (i < arr.length && tmp.map.containsKey(arr[i])){
      tmp = tmp.map.get(arr[i]);
      if (tmp.isend) {
        res = tmp.val;
      }
      i++;
    }
    if (res.length() == 0) return "/";
    return res;
  }

  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    String tmp = in.nextLine();
    while (!tmp.equals("-")){
      String[] arr = tmp.split(" ");
      insert(arr[0],arr[1]);
      tmp = in.nextLine();
    }
    while (in.hasNext()){
      tmp = in.nextLine();
      System.out.println(search(tmp));
    }
  }
}
